package com.example.testing.flags;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.testing.R;
import com.example.testing.launchmode.SingleInstanceActivity;
import com.example.testing.launchmode.SingleTaskActivity;
import com.example.testing.launchmode.StandardActivity;

/**
 * Intent.FLAG_ACTIVITY_SINGLE_TOP：这个标记位的作用和在xml中设置singleTop模式，效果一样
 *
 * 该模式和FLAG_ACTIVITY_CLEAR_TOP组合使用，可以实现类似singleTask的效果，当实例已经存在，则清除其上当Activity,
 * 并调用onNewIntent方法，并不能开辟新当任务栈
 */
public class SingleTopActivity extends Activity {
    private static final String TAG = "SingleTopActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.e(TAG, "onCreate: ");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flags_singletop);
        findViewById(R.id.tv_flags).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SingleTopActivity.this, SingleTopActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onNewIntent(Intent intent) {
        Log.e(TAG, "onNewIntent: ");
        super.onNewIntent(intent);
    }
}
